package com.yfp.client.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfp.client.domain.ActivitySignInsRules;
import com.yfp.client.mapper.ActivitySignInsRulesMapper;
import com.yfp.client.service.ActivitySignInsRulesService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @description 针对表【activity_sign_ins_rules(打卡管理-打卡规则表)】的数据库操作Service实现
 * @createDate 2025-01-03 17:46:13
 */
@Service
public class ActivitySignInsRulesServiceImpl extends ServiceImpl<ActivitySignInsRulesMapper, ActivitySignInsRules> implements ActivitySignInsRulesService {

    @Resource
    private ActivitySignInsRulesMapper activitySignInsRulesMapper;

    @Override
    public List<ActivitySignInsRules> listByActivitySignInsId(Long id) {
        return activitySignInsRulesMapper.listByActivitySignInsId(id);
    }

    @Override
    public void salesDeduction(Long activitySignInsRulesId) {
        ActivitySignInsRules activitySignInsRules = activitySignInsRulesMapper.selectById(activitySignInsRulesId);
        activitySignInsRulesMapper.updateResidualInventory(activitySignInsRulesId, activitySignInsRules.getDistributionQuantity());
    }

    @Override
    public Boolean checkStock(Long activitySignInsRulesId) {
        ActivitySignInsRules activitySignInsRules = activitySignInsRulesMapper.selectById(activitySignInsRulesId);
        return activitySignInsRules.getResidualInventory() >= activitySignInsRules.getDistributionQuantity();
    }
}




